package com.dkm.ec.home.domain;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.dkm.base.api.helper.IConfigHelper;
import com.dkm.base.core.helper.SpringHelper;
import com.dkm.biz.domain.AbstractDomain;
import com.dkm.ec.home.HomeOrderUtil;
import com.dkm.ec.home.persistence.dao.HomeOrderDao;
import com.dkm.ec.home.persistence.entity.HomeOrderPo;
import com.dkm.ec.home.repository.HomeOrderRepository;

/**
 * 对象功能:预约 领域对象实体
 * 开发公司:SKG.COM
 * 开发人员:胡协斌
 * 创建时间:2014-12-23 14:33:21
 */
@Service
@Scope("prototype")
public class HomeOrder extends AbstractDomain<String, HomeOrderPo>{
	 
	 private HomeOrderDao homeOrderDao = null;
	 
	 private HomeOrderRepository homeOrderRepository = null;

	protected void init(){
		homeOrderDao = SpringHelper.getBean(HomeOrderDao.class);
		homeOrderRepository = SpringHelper.getBean(HomeOrderRepository.class);
		setDao(homeOrderDao);
	}	 
	
	public synchronized void save(){		
		HomeOrderPo homeOrderPo=getData();
		//获取最后一条预约
		HomeOrder last=homeOrderRepository.getLast();
		
		//获取服务机器号
		IConfigHelper configHelper = SpringHelper.getBean(IConfigHelper.class);
		String machineId = configHelper.getParamValue("machine.id");
		
		//获取新流水号
		String lastOrderNo = last==null?"":last.getData().getOrderNo();
		String orderNo = HomeOrderUtil.buildOrderNo(lastOrderNo, machineId);		
		
		homeOrderPo.setOrderNo(orderNo);
		
		super.save();
	}
	
}
